import os

def count_csv_lines_in_2025_07_folders():
    root_dir = '/data/GuoCu_data/raw_data'
    total_lines = 0

    # 遍历根目录下的所有文件和文件夹
    for entry in os.listdir(root_dir):
        full_path = os.path.join(root_dir, entry)
        # 检查是否是以2025-07为前缀的文件夹
        if os.path.isdir(full_path) and entry.startswith('2025-07'):
            # 遍历该文件夹下的所有文件
            for root, _, files in os.walk(full_path):
                for file in files:
                    if file.endswith('.csv'):
                        csv_path = os.path.join(root, file)
                        try:
                            with open(csv_path, 'r', encoding='utf-8') as f:
                                # 统计文件行数
                                lines = sum(1 for _ in f)
                                total_lines += lines
                        except Exception as e:
                            print(f"读取文件 {csv_path} 时出错: {e}")

    return total_lines

if __name__ == "__main__":
    result = count_csv_lines_in_2025_07_folders()
    print(f"以2025-07为前缀命名的所有文件夹内所有csv文件的总行数为: {result}")
